package queue_stack.leetcode.easy;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author bruin_du
 * @description 滑动窗口的平均值
 * @date 2022/8/13 21:51
 **/
public class OfferII041_MovingAverage {
    Queue<Integer> queue;
    int size;
    int res;
    /** Initialize your data structure here. */
    public OfferII041_MovingAverage(int size) {
        queue = new LinkedList<>();
        this.size = size;
    }

    public double next(int val) {
        if (queue.size() == size) {
            res -= queue.poll();
        }
        queue.offer(val);
        res += val;
        return 1.0 * res / queue.size();
    }
}
